﻿using System.Collections.Generic;
using System.Runtime.Serialization;

namespace RockBus.DataContracts
{
    [DataContract(Namespace = StringConstants.RockBusNamespace)]
    public class SubscriptionInfo : EvaluationElementInfoBase<SubscriptionDetail>
    {
        private SubscriptionInfo()
            : base()
        {
        }

        public SubscriptionInfo(SubscriberInfo subscriberInfo, SubscriptionDetail subscriptionDetail, IEnumerable<string> filterIds)
            : base(subscriptionDetail, filterIds)
        {
            this.SubscriberInfo = subscriberInfo;
        }

        public SubscriptionInfo(SubscriberInfo subscriberInfo, SubscriptionDetail subscriptionDetail, params string[] filterIds)
            : this(subscriberInfo, subscriptionDetail, (IEnumerable<string>)filterIds)
        {
        }

        [IgnoreDataMember]
        public SubscriberInfo SubscriberInfo { get; set; }

        public IEnumerable<FilterInfo> GetFilterInfoEnumerator()
        {
            foreach (string filterId in this.FilterIds)
            {
                yield return this.SubscriberInfo.FilterInfoDictionary[filterId];
            }
        }

        [IgnoreDataMember]
        public EndpointInfo EndpointInfo
        {
            get { return this.SubscriberInfo.EndpointInfoDictionary[this.Detail.EndpointId]; }
        }
    }
}